import ExamComponent, { UsageComponent, UseComponent } from "@components/Apps/Exam/ExamComponent";
import ExamSettings from "@components/Apps/Exam/ExamSettings";
import GameObjectComponent from "@runtime/UnityEngineBridge/GameObjectComponent";
import { ClientMessage } from "@runtime/generate/message/ClientMessage";
import DeviceComponent from "@runtime/module/Device/DeviceComponent";
import MessageHandler from "@runtime/module/Handler/MessageHandler";
import WebSocketComponent from "@runtime/module/WebSocket/WebSocketComponent";
import { ref } from "vue";

const DeviceId = ref()
function longToNumber(longValue: any): number {
    const { low, high, unsigned } = longValue;
  
    if (unsigned) {
        DeviceId.value = (high >>> 0) * 4294967296 + (low >>> 0)
        return (high >>> 0) * 4294967296 + (low >>> 0);
    } else {        
        DeviceId.value = high * 4294967296 + (low >>> 0)
        console.log('DeviceId.value',DeviceId.value);
        return high * 4294967296 + (low >>> 0);
    }
  }

/**
 * 设备更新消息处理器
 */
export default class DeviceUpdateMessageHandler extends MessageHandler<ClientMessage.DeviceUpdateMessage> {
    protected async RunAsync(message: ClientMessage.DeviceUpdateMessage): Promise<void> {
        console.log('设备状态',message.Informations);
        if(message.Informations[0].Name == '激光雷达') {
            ExamComponent.Default.LaserDeviceStatus.value = message.Informations[0].Status
            if(ExamComponent.Default.LaserDeviceStatus.value == '设备连接成功' && ExamComponent.Default.DeviceName.value == 'PointCloudSet') {
                UseComponent.Default.Destroy()
                UseComponent.Default.Awake()
            }
        }
        if(message.Informations[0].Name == '双目相机') {
            console.log(message.Informations[0].Name,message.Informations[0].Status);
            
            ExamComponent.Default.BinDeviceStatus.value = message.Informations[0].Status
            if(message.Informations[0].Status == '设备连接成功' && ExamComponent.Default.DeviceName.value == 'Usage') {
                await WebSocketComponent.Default.PostMessageAsync(new ClientMessage.BinocularCameraLaneDetectionOpenRequest('0'));
            }
        }
        if(message.Informations[0].Name == '毫米波') {
            ExamComponent.Default.MMWRDeviceStatus.value = message.Informations[0].Status
        }
        // 什么作用？？忘记了
        DeviceComponent.Default.Update(message.Informations);

    }
}


